package com.meng.ioc_demo;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.meng.baselibrary.activity.BaseActivity;
import com.meng.baselibrary.adapter.BaseListViewAdapter;
import com.meng.ioclibrary.BindView;
import com.meng.ioclibrary.OnClick;
import com.meng.ioclibrary.ViewUtils;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity {
    @BindView(R.id.listView)
    private ListView mListView;
    private MyAdapter mAdapter;
    @BindView(R.id.btn)
    Button button;
    @OnClick(R.id.btn)
    public void onClick(View view){
        Toast.makeText(this, "button1", Toast.LENGTH_SHORT).show();
    }
    @BindView(R.id.btn2)
    Button button2;
    @OnClick(R.id.btn2)
    public void onClick2(View view){
        Toast.makeText(this, "button2", Toast.LENGTH_SHORT).show();
    }
    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void initTitle() {

    }

    @Override
    protected void initView() {
        ViewUtils.inject(this);
        mAdapter = new MyAdapter(this);
        mListView.setAdapter(mAdapter);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                startActivity(mAdapter.getItem(position).clazz);
            }
        });
    }

    @Override
    protected void initData() {
        mAdapter.addDatas(getDatas());
    }

    private List<Item> getDatas() {
        List<Item> list = new ArrayList<>();
        list.add(new Item("Dialog测试",DialogTestAty.class));
        list.add(new Item("BaseListViewAdapter测试",BaseListViewAdapterTestAty.class));
        list.add(new Item("BaseRecyclerViewAdapter测试",BaseRecyclerViewAdapterTestAty.class));
        list.add(new Item("启动一个没有注册的Activity",UnregistActivity.class));
        list.add(new Item("启动插件APK",ProxyActivity.class));
        return list;
    }

    private class Item{
        String title;
        Class<?> clazz;

        public Item(String title, Class<?> clazz) {
            this.title = title;
            this.clazz = clazz;
        }
    }
    private class MyAdapter extends BaseListViewAdapter<Item>{

        public MyAdapter(Context context) {
            super(context);
        }

        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new ItemViewHolder(getInflater().inflate(android.R.layout.simple_list_item_1,null));
        }

        @Override
        protected void onBindViewHolder(ViewHolder holder, int position) {
            ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
            itemViewHolder.textView.setText(getItem(position).title);
        }
        private class ItemViewHolder extends BaseListViewAdapter.ViewHolder{
            TextView textView;
            public ItemViewHolder(View itemView) {
                super(itemView);
                textView = (TextView) itemView.findViewById(android.R.id.text1);
            }
        }
    }
}
